home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 24
/
Aminet 24 (1998)(GTI - Schatztruhe)[!][Apr 1998].iso
/
Aminet
/
comm
/
mail
/
Mutt089src.lha
/
Mutt-0.89i-AMIGA
/
src
/
menu.c
< prev
next >
Wrap
C/C++ Source or Header
|
1998-01-28
|
17KB
|
793 lines
/*
* Copyright (C) 1996-8 Michael R. Elkins <me@cs.hmc.edu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "mutt.h"
#include "mutt_curses.h"
#include "mutt_menu.h"
#include <string.h>
#include <stdlib.h>
#define M_MODEFMT "-- Mutt: %s"
static void print_enriched_string (unsigned char *s, int do_color)
{
while (*s)
{
if (*s < ctrl ('I'))
{
if (do_color)
SETCOLOR (MT_COLOR_TREE);
while (*s && *s < ctrl ('I'))
{
switch (*s)
{
case 1:
addch (option (OPTASCIICHARS) ? '`' : ACS_LLCORNER);
break;
case 2:
addch (option (OPTASCIICHARS) ? ',' : ACS_ULCORNER);
break;
case 3:
addch (option (OPTASCIICHARS) ? '|' : ACS_LTEE);
break;
case 4:
addch (option (OPTASCIICHARS) ? '-' : ACS_HLINE);
break;
case 5:
addch (option (OPTASCIICHARS) ? '|' : ACS_VLINE);
break;
case 6:
addch (' ');
break;
case 7:
addch ('>');
break;
case 8:
addch ('*'); /* fake thread indicator */
break;
}
s++;
}
if (do_color)
SETCOLOR (MT_COLOR_NORMAL);
}
else
{
addch (*s);
s++;
}
}
}
void menu_pad_string (char *s, size_t l)
{
#if !defined(HAVE_BKGDSET) && !defined (USE_SLANG_CURSES)
int n = strlen (s);
#endif
int shift = option (OPTARROWCURSOR) ? 3 : 0;
l--; /* save room for the terminal \0 */
if (l > COLS - shift)
l = COLS - shift;
#if !defined (HAVE_BKGDSET) && !defined (USE_SLANG_CURSES)
/* we have to pad the string with blanks to the end of line */
if (n < l)
{
while (n < l)
s[n++] = ' ';
s[n] = 0;
}
else
#endif
s[l] = 0;
}
void menu_redraw_full (MUTTMENU *menu)
{
SETCOLOR (MT_COLOR_NORMAL);
/* clear() doesn't optimize screen redraws */
move (0, 0);
clrtobot ();
if (option (OPTHELP))
{
SETCOLOR (MT_COLOR_STATUS);
mvprintw (option (OPTSTATUSONTOP) ? LINES-2 : 0, 0, "%-*.*s", COLS, COLS, menu->help);
SETCOLOR (MT_COLOR_NORMAL);
menu->offset = 1;
menu->pagelen = LINES - 3;
}
else
{
menu->offset = option (OPTSTATUSONTOP) ? 1 : 0;
menu->pagelen = LINES - 2;
}
mutt_show_error ();
menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
}
void menu_redraw_index (MUTTMENU *menu)
{
char buf[STRING];
int i;
for (i = menu->top; i < menu->top + menu->pagelen; i++)
{
if (i < menu->max)
{
menu->make_entry (buf, sizeof (buf), menu, i);
menu_pad_string (buf, sizeof (buf));
if (option (OPTARROWCURSOR))
{
CLEARLINE (i - menu->top + menu->offset);
if (i == menu->current)
{
SETCOLOR (MT_COLOR_INDICATOR);
addstr ("->");
SETCOLOR (MT_COLOR_NORMAL);
addch (' ');
}
else
move (i - menu->top + menu->offset, 3);
print_enriched_string ((unsigned char *) buf, 1);
}
else
{
if (i == menu->current)
{
SETCOLOR (MT_COLOR_INDICATOR);
BKGDSET (MT_COLOR_INDICATOR);
}
CLEARLINE (i - menu->top + menu->offset);
print_enriched_string ((unsigned char *) buf, i != menu->current);
if (i == menu->current)
{
SETCOLOR (MT_COLOR_NORMAL);
BKGDSET (MT_COLOR_NORMAL);
}
}
}
else
CLEARLINE (i - menu->top + menu->offset);
}
menu->redraw = 0;
}
void menu_redraw_motion (MUTTMENU *menu)
{
char buf[STRING];
move (menu->oldcurrent + menu->offset - menu->top, 0);
SETCOLOR (MT_COLOR_NORMAL);
BKGDSET (MT_COLOR_NORMAL);
if (option (OPTARROWCURSOR))
{
/* clear the pointer */
addstr (" ");
if (menu->redraw & REDRAW_MOTION_RESYNCH)
{
clrtoeol ();
menu->make_entry (buf, sizeof (buf), menu, menu->oldcurrent);
menu_pad_string (buf, sizeof (buf));
move (menu->oldcurrent + menu->offset - menu->top, 3);
print_enriched_string ((unsigned char *) buf, 1);
}
/* now draw it in the new location */
move (menu->current + menu->offset - menu->top, 0);
SETCOLOR (MT_COLOR_INDICATOR);
addstr ("->");
SETCOLOR (MT_COLOR_NORMAL);
}
else
{
/* erase the current indicator */
clrtoeol ();
menu->make_entry (buf, sizeof (buf), menu, menu->oldcurrent);
menu_pad_string (buf, sizeof (buf));
print_enriched_string ((unsigned char *) buf, 1);
/* now draw the new one to reflect the change */
menu->make_entry (buf, sizeof (buf), menu, menu->current);
menu_pad_string (buf, sizeof (buf));
SETCOLOR (MT_COLOR_INDICATOR);
BKGDSET (MT_COLOR_INDICATOR);
CLEARLINE (menu->current - menu->top + menu->offset);
print_enriched_string ((unsigned char *) buf, 0);
SETCOLOR (MT_COLOR_NORMAL);
BKGDSET (MT_COLOR_NORMAL);
}
menu->redraw = 0;
}
void menu_redraw_current (MUTTMENU *menu)
{
char buf[STRING];
move (menu->current + menu->offset - menu->top, 0);
menu->make_entry (buf, sizeof (buf), menu, menu->current);
menu_pad_string (buf, sizeof (buf));
if (option (OPTARROWCURSOR))
{
clrtoeol ();
SETCOLOR (MT_COLOR_INDICATOR);
addstr ("->");
SETCOLOR (MT_COLOR_NORMAL);
addch (' ');
menu_pad_string (buf, sizeof (buf));
print_enriched_string ((unsigned char *) buf, 1);
}
else
{
SETCOLOR (MT_COLOR_INDICATOR);
BKGDSET (MT_COLOR_INDICATOR);
clrtoeol ();
print_enriched_string ((unsigned char *) buf, 0);
SETCOLOR (MT_COLOR_NORMAL);
BKGDSET (MT_COLOR_NORMAL);
}
menu->redraw = 0;
}
void menu_check_recenter (MUTTMENU *menu)
{
if (menu->current >= menu->top + menu->pagelen)
{
if (option (OPTMENUSCROLL))
menu->top = menu->current - menu->pagelen + 1;
else
menu->top += menu->pagelen * ((menu->current - menu->top) / menu->pagelen);
menu->redraw = REDRAW_INDEX;
}
else if (menu->current < menu->top)
{
if (option (OPTMENUSCROLL))
menu->top = menu->current;
else
{
menu->top -= menu->pagelen * ((menu->top + menu->pagelen - 1 - menu->current) / menu->pagelen);
if (menu->top < 0)
menu->top = 0;
}
menu->redraw = REDRAW_INDEX;
}
}
void menu_jump (MUTTMENU *menu)
{
int n;
char buf[SHORT_STRING];
if (menu->max)
{
mutt_ungetch (LastKey);
buf[0] = 0;
if (mutt_get_field ("Jump to: ", buf, sizeof (buf), 0) == 0 && buf[0])
{
n = atoi (buf) - 1;
if (n >= 0 && n < menu->max)
{
menu->current = n;
menu->redraw = REDRAW_MOTION;
}
else
mutt_error ("Invalid index number.");
}
}
else
mutt_error ("No entries.");
}
void menu_next_line (MUTTMENU *menu)
{
if (menu->max)
{
if (menu->top < menu->max - 1)
{
menu->top++;
if (menu->current < menu->top)
menu->current++;
menu->redraw = REDRAW_INDEX;
}
else
mutt_error ("You cannot scroll down farther.");
}
else
mutt_error ("No entries.");
}
void menu_prev_line (MUTTMENU *menu)
{
if (menu->top > 0)
{
menu->top--;
if (menu->current >= menu->top + menu->pagelen)
menu->current--;
menu->redraw = REDRAW_INDEX;
}
else
mutt_error ("You cannot scroll up farther.");
}
void menu_next_page (MUTTMENU *menu)
{
if (menu->max)
{
if (menu->top + menu->pagelen < menu->max)
{
menu->top += menu->pagelen;
if (menu->current < menu->top)
menu->current = menu->top;
menu->redraw = REDRAW_INDEX;
}
else if (menu->current != menu->max - 1)
{
menu->current = menu->max - 1;
menu->redraw = REDRAW_MOTION;
}
else
mutt_error ("You are on the last page.");
}
else
mutt_error ("No entries.");
}
void menu_prev_